package com.file.manage.controller;


import com.file.manage.domain.data.UserFileMappingVO;
import com.file.manage.domain.request.SavePower;
import com.file.manage.domain.service.UserFileMappingService;
import com.file.manage.infrastructure.base.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @since 2025-05-22
 */
@RestController
@RequestMapping("logs")
@Tag(name = "用户文件关联相关接口")
public class UserFileMappingController {
    @Resource
    private UserFileMappingService userFileMappingService;


    @Operation(summary = "通过文件id查询")
    @GetMapping(value = "/listByFileId")
    public CommonResult<List<UserFileMappingVO>> listByFileId(@RequestParam("fileId") String fileId) {
        return CommonResult.success(userFileMappingService.listByFileId(fileId));
    }

    @Operation(summary = "通过用户id查询")
    @GetMapping(value = "/listByUserId")
    public CommonResult<List<UserFileMappingVO>> listByUserId(@RequestParam("userId") String userId) {
        return CommonResult.success(userFileMappingService.listByUserId(userId));
    }

    @Operation(summary = "保存")
    @PostMapping(value = "/save")
    public CommonResult<?> saveA(@RequestBody SavePower savePower) {
        userFileMappingService.save(savePower.getUserId(), savePower.getFileIds());
        return CommonResult.success();
    }

    @Operation(summary = "删除")
    @DeleteMapping(value = "/delete")
    public CommonResult<?> delete(@RequestParam("id") String id) {
        userFileMappingService.removeById(id);
        return CommonResult.success();
    }

}
